﻿Public Class FrmConnection

    Dim macnx As New PPE3.ClassMySqlConnect("853339_depanneur", "071064")

    Private Sub FrmConnection_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = FrmStart
        Me.CenterToScreen()
        macnx.Se_Connecter_MySqlServer()
        macnx.Chargement_ComboBox(ComboBoxNom, "SELECT NomCompte , isAdmin FROM compte", "USER", "isAdmin", "NomCompte")
        macnx.Se_Deconnecter_MySqlServer()
    End Sub

    
    Private Sub BtnValider_Click(sender As System.Object, e As System.EventArgs) Handles BtnValider.Click
        Try

            Dim Nom As String = ComboBoxNom.Text
            Dim Admin As String = ComboBoxNom.SelectedValue.ToString
            Dim id As String
            Dim psw As String = TextBoxMDP.Text

            macnx.Se_Connecter_MySqlServer()
            id = macnx.ExecuteScalar("SELECT idCompte FROM compte WHERE (NomCompte LIKE '" & Nom & "' ) AND (MDPCompte LIKE '" & psw & "') ")
            macnx.Se_Deconnecter_MySqlServer()

            If id <> "" Then
                FrmStart.ListeDepannagesToolStripMenuItem.Enabled = True
                FrmStart.RechercheDepannageToolStripMenuItem.Enabled = True
                FrmStart.AjoutDepannageToolStripMenuItem.Enabled = True
                FrmStart.ModificationDuFormulaireDepannageToolStripMenuItem.Enabled = True
                FrmStart.ListeClientToolStripMenuItem1.Enabled = True
                FrmStart.RechercheClientToolStripMenuItem1.Enabled = True
                FrmStart.ListeTarifsToolStripMenuItem2.Enabled = True
                FrmStart.AjoutModifSuppTravauxToolStripMenuItem.Enabled = True
                FrmStart.ListeMaterielToolStripMenuItem3.Enabled = True
                FrmStart.AjoutSupprModifMaterielToolStripMenuItem.Enabled = True
                'FrmStart.PieceDOcasionToolStripMenuItem.Enabled = True
                FrmStart.InterventionsEnCoursToolStripMenuItem.Enabled = True
                FrmStart.ModifMotDePasseToolStripMenuItem.Enabled = True

                If Admin = True Then

                    FrmStart.ModifAdminToolStripMenuItem.Enabled = False
                    FrmStart.InterventionsTerminéesToolStripMenuItem.Enabled = False
                    FrmStart.MenuIdent.Text = ComboBoxNom.Text
                    FrmDepEnCours.Show()
                    Me.Hide()

                ElseIf Admin = False Then

                    FrmStart.ModifAdminToolStripMenuItem.Enabled = True
                    FrmStart.InterventionsTerminéesToolStripMenuItem.Enabled = True
                    FrmStart.MenuIdent.Text = ComboBoxNom.Text
                    FrmDepEnCours.Show()
                    FrmDepTerm.Show()
                    Me.Hide()

                Else
                    MessageBox.Show("Entrer un Nom et un mot de passe valide !", "", MessageBoxButtons.OK, MessageBoxIcon.Hand)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show("Entrer un Nom et un mot de passe valide !", "", MessageBoxButtons.OK, MessageBoxIcon.Hand)
        End Try


    End Sub


    Private Sub TextBoxNom_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs)
        If (e.KeyCode = Keys.Enter) Then
            BtnValider.PerformClick()
        End If
    End Sub

    Private Sub TextBoxMDP_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBoxMDP.KeyDown
        If (e.KeyCode = Keys.Enter) Then
            BtnValider.PerformClick()
        End If
    End Sub


End Class